package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertFiledCustomerDO;
import cqrtplm.service.RtCertFiledCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 备案客户信息控制器
 */
@RestController
@Api(tags = "认证-备案客户信息")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/customer/" + "v1")
public class RtCertFiledCustomerController {

    @Autowired
    private RtCertFiledCustomerService rtCertFiledCustomerService;

    /**
     * 查询备案客户信息列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "list", notes = "获取备案客户信息列表")
    public ResponseResult list(@RequestBody RtCertFiledCustomerDO rtCertFiledCustomer) {
        List<RtCertFiledCustomerDO> list = rtCertFiledCustomerService.selectRtCertFiledCustomerList(rtCertFiledCustomer);
        return ResponseResult.success(list);
    }

    /**
     * 分页查询备案客户信息列表
     */
    @PostMapping("/pagelist")
    @ApiOperation(value = "pagelist", notes = "分页获取备案客户信息列表")
    public ResponseResult<PageInfo<RtCertFiledCustomerDO>> pagelist(
            @RequestBody RtCertFiledCustomerDO rtCertFiledCustomer,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertFiledCustomerDO> list = rtCertFiledCustomerService.selectRtCertFiledCustomerList(rtCertFiledCustomer);
        PageInfo<RtCertFiledCustomerDO> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    /**
     * 导出备案客户信息列表
     */
    @PostMapping("/export")
    @ApiOperation(value = "export", notes = "导出备案客户信息列表")
    public void export(HttpServletResponse response, RtCertFiledCustomerDO rtCertFiledCustomer) {
        List<RtCertFiledCustomerDO> list = rtCertFiledCustomerService.selectRtCertFiledCustomerList(rtCertFiledCustomer);
        // ExcelUtil.listToExcel(list, RtCertFiledCustomerDO.class, wwb, "备案客户信息数据");
    }

    /**
     * 获取备案客户信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "getInfo", notes = "获取备案客户信息详情")
    public ResponseResult getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(rtCertFiledCustomerService.selectRtCertFiledCustomerById(id));
    }

    /**
     * 新增备案客户信息
     */
    @PostMapping("/add")
    @ApiOperation(value = "add", notes = "新增备案客户信息")
    public ResponseResult add(@RequestBody RtCertFiledCustomerDO rtCertFiledCustomer) {
        return ResponseResult.success(rtCertFiledCustomerService.insertRtCertFiledCustomer(rtCertFiledCustomer));
    }

    /**
     * 修改备案客户信息
     */
    @PostMapping("/edit")
    @ApiOperation(value = "edit", notes = "修改备案客户信息")
    public ResponseResult edit(@RequestBody RtCertFiledCustomerDO rtCertFiledCustomer) {
        return ResponseResult.success(rtCertFiledCustomerService.updateRtCertFiledCustomer(rtCertFiledCustomer));
    }

    /**
     * 删除备案客户信息
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "delete", notes = "删除备案客户信息")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertFiledCustomerService.deleteRtCertFiledCustomerByIds(ids));
    }

    /**
     * 根据客户代码查询备案客户信息
     */
    @GetMapping("/getcustomer")
    @ApiOperation(value = "getByDO", notes = "根据客户查询备案客户信息")
    public ResponseResult getByDO(@RequestParam("model") String model,@RequestParam("ctype") String ctype,@RequestParam("khmc") String khmc) {
         RtCertFiledCustomerDO rtCertFiledCustomer = new RtCertFiledCustomerDO();
        rtCertFiledCustomer.setCtype(ctype);
        rtCertFiledCustomer.setModel(model);
        rtCertFiledCustomer.setKhmc(khmc);
        return ResponseResult.success(rtCertFiledCustomerService.selectRtCertFiledCustomerByDO(rtCertFiledCustomer));
    }
}